<template>
    <view class="action-swiper">
        <van-action-sheet v-model:show="state.show" teleport="body" :actions="state.actions" cancel-text="取消"
            close-on-click-action :lazy-render="false" @cancel="state.show = false" @select="actionSheetFn" />
    </view>
</template>
    
<script setup>
import { reactive, ref, getCurrentInstance, onMounted } from "vue"
import { onLoad } from '@dcloudio/uni-app'
import { getAuthorization, setAuthorization } from "@/utils/auth.js"

import {
    LikeOrStep, // 获取某一条动态
} from "@/api/im/index.js"

import {
    setNoDisplayUser, // 拉黑
} from "@/api/person/index.js"

let { proxy } = getCurrentInstance()

let props = defineProps({
    actionsArr: {
        type: Array,
        default: () => []
    },
    currentItem: {
        type: Object,
        default: () => { }

    },
    imId: {
        type: Number,
        default: null
    }
})

let emits = defineEmits(['actionSuccess']) // 成功返回事件

const state = reactive({
    show: false,
    actions: props.actionsArr,
    UserId: 0,
})

onLoad((options) => {
    state.UserId = options.id
})

const actionSheetShow = () => {
    state.show = true
}

const unLike = async () => {
    let params = {
        userId: getAuthorization("userId"),
        likeType: 2
    }
    let data = await proxy.$post(LikeOrStep + props.currentItem.ID + '/LikeOrStep', params)
}

// 举报
const opinionFeedbackFn = () => {
    uni.navigateTo({
        url: '/pages/home/person/opinionFeedback/index?userId=' + props.currentItem.ID + '&type=2'
    })
}

// 清空聊天记录
import { useAccountStore } from "@/store/index.js"
const clearChatFn = () => {
    let store = useAccountStore()
    store.clearChatMsg(props.imId)
}


// 拉黑
const shieldFn = async () => {
    let data = await proxy.$post(setNoDisplayUser(props.currentItem.ID))
    if (data.code == 200) {
        emits('actionSuccess')
    }
}

// 不喜欢
const actionSheetFn = (ev) => {
    let { name } = ev
    if (name == "不喜欢") unLike()
    if (name == "举报") opinionFeedbackFn()
    if (name == "清空聊天记录") clearChatFn()
    if (name == "拉黑") shieldFn()
    if (name == "对他隐身") shieldFn()
}

defineExpose({
    actionSheetShow
})

</script>
    
<style lang="scss" scoped></style>
    